package me.search;

import java.util.ArrayList;

public class A01_BasicSearchDemo2 {
    public static void main(String[] args) {
        //定义一个方法利用基本查找，查询某个元素在数组中的索引
        //需要考虑；重复的元素
        int[] arr = {11, 12, 13, 12, 14, 15, 16};
        ArrayList<Integer> resultList = basicSearch(arr, 12);
        System.out.println(resultList);
    }

    public static ArrayList<Integer> basicSearch(int[] arr, int number) {
        //重复的元素放在集合中
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                list.add(i);
            }
        }
        return list;
    }
}
